package com.proj.hot.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.proj.hot.GlobalParams;
import com.proj.hot.R;
import com.proj.hot.activity.LoginActivity;
import com.proj.hot.activity.VODBuyPlayActivity;
import com.proj.hot.activity.webview.WebMainActivity;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

/**
 * 购物
 * Created by zangchenggang on 17/6/30.
 */
public class askFragment extends BaseFragment {

    private List<View> viewList = new ArrayList<>();
    private View shop_view1,morecon;
    private ImageView shop_poster1;
    JSONArray dataArray;
    String code;

    TextView lt1,lt2,lt3,lt4,lt5;
    TextView rt1,rt2,rt3,rt4,rt5;




    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 0) {


            }
        }
    };


    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

            getData();

    }


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_ask, container, false);
        shop_view1 = rootView.findViewById(R.id.shop_rl_poster1);
        morecon=rootView.findViewById(R.id.tips2);


        lt1=(TextView) rootView.findViewById(R.id.lt1);
        lt2=(TextView) rootView.findViewById(R.id.lt2);
        lt3=(TextView) rootView.findViewById(R.id.lt3);
        lt4=(TextView) rootView.findViewById(R.id.lt4);
        lt5=(TextView) rootView.findViewById(R.id.lt5);






        viewList.add(shop_view1);


        shop_poster1 = (ImageView) rootView.findViewById(R.id.shop_poster1);





        setOnListener();
        return rootView;
    }

    private void setOnListener() {

        for (int i = 0; i < viewList.size(); i++) {
            final int k = i;
            viewList.get(i).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    // if jsonarray type=13

                    Toast.makeText(getContext(),"暂未开放，敬请待期",Toast.LENGTH_SHORT).show();

//                    String url="";
//
//                    if(k==0){
//
//                        url=GlobalParams.HTML_PATH+"";
//                    }
//
//                        Intent intent = new Intent(getActivity().getApplicationContext(), WebMainActivity.class);
//
//
//                        intent.putExtra("weburl", url);
//
//                        startActivity(intent);

                }
            });
        }

        morecon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String url=GlobalParams.HTML_PATH+"page/1.0.6.html?code=fntv_flzx_lyzx";

                Intent intent = new Intent(getActivity().getApplicationContext(), WebMainActivity.class);


                intent.putExtra("weburl", url);

                startActivity(intent);

            }
        });



    }


    public void setCodeAndInitData(String code) {

        this.code = code;

    }


    private void getData() {

        try {


            /**
             * ---------------body------------------
             */
            JSONObject body = new JSONObject();
            body.put("code", "fntv_flzx_lyzx");
            body.put("sign", "1EDF0A41F91213D4341BE77783E0D07B");

            RequestParams params = new RequestParams(GlobalParams.reqHost_fntvol + "fntvol/getarticlelist");
            params.setAsJsonContent(true);
            params.setBodyContent(body.toString().trim());

            /**
             * ---------------send------------------
             */
            x.http().post(params, new org.xutils.common.Callback.CommonCallback<String>() {
                @Override
                public void onSuccess(String s) {
                    try {

                        System.out.print(s);
                        JSONObject jData = new JSONObject(s);
//
//                        JSONObject respbody = jData.getJSONObject("respbody");
                        dataArray = jData.getJSONArray("rows");
                        handler.sendEmptyMessage(0);

                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }

                @Override
                public void onFinished() {
                    System.out.print(8);
                }

                @Override
                public void onCancelled(CancelledException e) {
                    System.out.print(9);
                }

                @Override
                public void onError(Throwable throwable, boolean b) {
                    System.out.print(90);
                }
            });


        } catch (Exception e) {
            e.printStackTrace();
        }

    }





}
